﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.AdminPage
{
    public partial class FrmOrderEdit : WebCommon
    {
        public Model.tb_order model=new Model.tb_order();
        public List<Common.WebBindSelectHelper> select_Status_list = new List<Common.WebBindSelectHelper>();
 
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["Id"]!=null)
                {
                    if (Request.QueryString["Id"].Trim().Length > 0)
                    {
                        GetModel(Convert.ToInt32(Request.QueryString["Id"]));
                    }
                }
               
            }
        }
        public string GetNumber()
        {
            string newId = string.Empty;
            Model.tb_order data = Common.SqlExption.GetList<Model.tb_order>().OrderByDescending(c => c.Id).FirstOrDefault();
            if (data != null)
            {
                newId = DateTime.Now.ToString("yyyyMMdd") + "00" + (Convert.ToInt32(data.Id) + 1).ToString();
            }
            else
            {
                newId = DateTime.Now.ToString("yyyyMMdd") + "00" + (0 + 1).ToString();
            }

            return newId;

        }

        public void GetModel(int Id)
        {
            Model.tb_order data = Common.SqlExption.GetList<Model.tb_order>().FirstOrDefault(c => c.Id.Equals(Id));


            if (data!=null)
            {
                model = data;
            }
            else
            {
                model.Id = 0;
            }
            model.order_number = GetNumber();
            var select_list = Common.SqlExption.GetList<Model.tb_status>().Where(c=>c.stype.Equals(1));
            foreach (var item in select_list)
            {
                Common.WebBindSelectHelper m = new Common.WebBindSelectHelper();
                if (model.Id > 0)
                {
                    if (model.status.Equals(item.Id))
                    {
                        m.IsSelected = "Selected";
                    }
                }
                m.Value = item.Id.ToString();
                m.Text = item.name;
                select_Status_list.Add(m);

            }

        }
    }
}
